home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CDsupport / ClassAct / Examples / CheckBox / checkboxexample.c < prev    next >
C/C++ Source or Header  |  1997-04-27  |  5KB  |  234 lines

  1. ;/* CheckBox Example
  2. sc link checkboxexample.c lib lib:classact.lib
  3. quit
  4. */
  5.  
  6. /**
  7.  **  CheckBoxExample.c -- CheckBox class Example.
  8.  **
  9.  **  This is a simple example testing some of the capabilities of the
  10.  **  CheckBox gadget class.
  11.  **
  12.  **  This code opens a window and then creates 2 CheckBox gadgets which
  13.  **  are subsequently attached to the window's gadget list.  One uses
  14.  **  arrows, one does not.  Notice that you can tab cycle between them.
  15.  **/
  16.  
  17. /* system includes
  18.  */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #include <exec/types.h>
  24. #include <exec/memory.h>
  25. #include <intuition/intuition.h>
  26. #include <intuition/gadgetclass.h>
  27. #include <libraries/gadtools.h>
  28. #include <graphics/gfxbase.h>
  29. #include <graphics/text.h>
  30. #include <graphics/gfxmacros.h>
  31. #include <utility/tagitem.h>
  32. #include <workbench/startup.h>
  33. #include <workbench/workbench.h>
  34.  
  35. #include <proto/intuition.h>
  36. #include <proto/graphics.h>
  37. #include <proto/exec.h>
  38. #include <proto/dos.h>
  39. #include <proto/utility.h>
  40. #include <proto/wb.h>
  41. #include <proto/icon.h>
  42.  
  43. /* ClassAct includes
  44.  */
  45. #include <classact.h>
  46.  
  47.  
  48. enum
  49. {
  50.     GID_MAIN=0,
  51.     GID_CHECKBOX1,
  52.     GID_CHECKBOX2,
  53.     GID_DOWN,
  54.     GID_UP,
  55.     GID_QUIT,
  56.     GID_LAST
  57. };
  58.  
  59. enum
  60. {
  61.     WID_MAIN=0,
  62.     WID_LAST
  63. };
  64.  
  65. enum
  66. {
  67.     OID_MAIN=0,
  68.     OID_LAST
  69. };
  70.  
  71. int main(void)
  72. {
  73.     struct MsgPort *AppPort;
  74.  
  75.     struct Window *windows[WID_LAST];
  76.  
  77.     struct Gadget *gadgets[GID_LAST];
  78.  
  79.     Object *objects[OID_LAST];
  80.  
  81.     /* make sure our classes opened... */
  82.     if (!ButtonBase || !CheckBoxBase || !WindowBase || !LayoutBase)
  83.         return(30);
  84.     else if ( AppPort = CreateMsgPort() )
  85.     {
  86.         /* Create the window object.
  87.          */
  88.         objects[OID_MAIN] = WindowObject,
  89.             WA_ScreenTitle, "ClassAct Release 2.0",
  90.             WA_Title, "ClassAct CheckBox Example",
  91.             WA_Activate, TRUE,
  92.             WA_DepthGadget, TRUE,
  93.             WA_DragBar, TRUE,
  94.             WA_CloseGadget, TRUE,
  95.             WA_SizeGadget, TRUE,
  96.             WINDOW_IconifyGadget, TRUE,
  97.             WINDOW_IconTitle, "CheckBox",
  98.             WINDOW_AppPort, AppPort,
  99.             WINDOW_Position, WPOS_CENTERMOUSE,
  100.             WINDOW_ParentGroup, gadgets[GID_MAIN] = VGroupObject,
  101.                 LAYOUT_SpaceOuter, TRUE,
  102.                 LAYOUT_DeferLayout, TRUE,
  103.  
  104.                 LAYOUT_AddChild, gadgets[GID_CHECKBOX1] = CheckBoxObject,
  105.                     GA_ID, GID_CHECKBOX1,
  106.                     GA_RelVerify, TRUE,
  107.                     GA_Text, "CheckBox _1",
  108.                     CHECKBOX_TextPlace, PLACETEXT_RIGHT,
  109.                 CheckBoxEnd,
  110.                 CHILD_NominalSize, TRUE,
  111.  
  112.                 LAYOUT_AddChild, gadgets[GID_CHECKBOX2] = CheckBoxObject,
  113.                     GA_ID, GID_CHECKBOX2,
  114.                     GA_RelVerify, TRUE,
  115.                     GA_Text, "CheckBox _2",
  116.                     CHECKBOX_TextPlace, PLACETEXT_LEFT,
  117.                 CheckBoxEnd,
  118.  
  119.                 LAYOUT_AddChild, VGroupObject,
  120.                     CLASSACT_BackFill, NULL,
  121.                     LAYOUT_SpaceOuter, TRUE,
  122.                     LAYOUT_VertAlignment, LALIGN_CENTER,
  123.                     LAYOUT_HorizAlignment, LALIGN_CENTER,
  124.                     LAYOUT_BevelStyle, BVS_FIELD,
  125.  
  126.                     LAYOUT_AddImage, LabelObject,
  127.                         LABEL_Text, "The checkbox may have its label placed\n",
  128.                         LABEL_Text, "either on the left or right side.\n",
  129.                         LABEL_Text, " \n",
  130.                         LABEL_Text, "You may click the label text as well\n",
  131.                         LABEL_Text, "as the check box itself.\n",
  132.                     LabelEnd,
  133.                 LayoutEnd,
  134.  
  135.                 LAYOUT_AddChild, ButtonObject,
  136.                     GA_ID, GID_QUIT,
  137.                     GA_RelVerify, TRUE,
  138.                     GA_Text,"_Quit",
  139.                 ButtonEnd,
  140.                 CHILD_WeightedHeight, 0,
  141.  
  142.             EndGroup,
  143.         EndWindow;
  144.  
  145.          /*  Object creation sucessful?
  146.           */
  147.         if (objects[OID_MAIN])
  148.         {
  149.             /*  Open the window.
  150.              */
  151.             if (windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]))
  152.             {
  153.                 ULONG wait, signal, app = (1L << AppPort->mp_SigBit);
  154.                 ULONG done = FALSE;
  155.                 ULONG result;
  156.                 UWORD code;
  157.  
  158.                  /* Obtain the window wait signal mask.
  159.                  */
  160.                 GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  161.  
  162.                 /* Input Event Loop
  163.                  */
  164.                 while (!done)
  165.                 {
  166.                     wait = Wait( signal | SIGBREAKF_CTRL_C | app );
  167.  
  168.                     if ( wait & SIGBREAKF_CTRL_C )
  169.                     {
  170.                         done = TRUE;
  171.                     }
  172.                     else
  173.                     {
  174.                         while ( (result = CA_HandleInput(objects[OID_MAIN], &code) ) != WMHI_LASTMSG )
  175.                         {
  176.                             switch (result & WMHI_CLASSMASK)
  177.                             {
  178.                                 case WMHI_CLOSEWINDOW:
  179.                                     windows[WID_MAIN] = NULL;
  180.                                     done = TRUE;
  181.                                     break;
  182.  
  183.                                 case WMHI_GADGETUP:
  184.                                     switch (result & WMHI_GADGETMASK)
  185.                                     {
  186.                                         case GID_CHECKBOX1:
  187.                                             /* code is TRUE or FALSE depending on check state */
  188.                                             break;
  189.  
  190.                                         case GID_CHECKBOX2:
  191.                                             /* code is TRUE or FALSE depending on check state */
  192.                                             break;
  193.  
  194.                                         case GID_QUIT:
  195.                                             done = TRUE;
  196.                                             break;
  197.                                     }
  198.                                     break;
  199.  
  200.                                 case WMHI_ICONIFY:
  201.                                     CA_Iconify(objects[OID_MAIN]);
  202.                                     windows[WID_MAIN] = NULL;
  203.                                     break;
  204.  
  205.                                 case WMHI_UNICONIFY:
  206.                                     windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]);
  207.  
  208.                                     if (windows[WID_MAIN])
  209.                                     {
  210.                                         GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  211.                                     }
  212.                                     else
  213.                                     {
  214.                                         done = TRUE;    // error re-opening window!
  215.                                     }
  216.                                      break;
  217.                             }
  218.                         }
  219.                     }
  220.                 }
  221.             }
  222.  
  223.             /* Disposing of the window object will also close the window if it is
  224.              * already opened, and it will dispose of the layout object attached to it.
  225.              */
  226.             DisposeObject(objects[OID_MAIN]);
  227.         }
  228.  
  229.         DeleteMsgPort(AppPort);
  230.     }
  231.  
  232.     return(0);
  233. }
  234.